﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Maticsoft.DAL
{
	/// <summary>
	/// 数据访问类:Comments
	/// </summary>
	public partial class Comments
	{
        public int DeleteByIds(string ids)
        {
            string strSql = "Update Comments set IsActive=0 where CommentId in (" + ids + ")";

            return DbHelperSQL.ExecuteSql(strSql);
        }

        public int AuditByIds(string ids)
        {
            string strSql = "Update Comments set ShowStatus=1 where CommentId in (" + ids + ")";

            return DbHelperSQL.ExecuteSql(strSql);
        }

        public DataSet GetListV(string strWhere)
        {
            string strSql = "select * from v_Comments";
            if (strWhere != "")
            {
                strSql += " where " + strWhere;
            }

            return DbHelperSQL.Query(strSql);
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCountV(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM v_Comments ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPageV(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.CommentId desc");
            }
            strSql.Append(")AS Row, T.*  from v_Comments T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }
	}
}

